package net.hn.hnms.biz.mine.service;

import org.smartboot.socket.MessageProcessor;
import org.smartboot.socket.transport.AioQuickClient;
import org.smartboot.socket.transport.AioSession;
import org.smartboot.socket.transport.WriteBuffer;

import java.io.IOException;
import java.util.UUID;

/**
 * 智呈物联 pan'sx
 * 2022/9/7 14:53
 * 1.0 version
 */
public class StringClient {
    public static volatile  AioQuickClient client=null;
    public static void main2(String[] args) throws IOException {
        String uuid = UUID.randomUUID().toString();
        String message="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<broadcast>\n" +
                "   <cmd>start</cmd>\n" +
                "   <uuid>"+uuid+"</uuid>\n" +
                "   <subject>联动广播</subject>\n" +
                "   <cyclicmode>0</cyclicmode>\n" +
                "   <starttime></starttime>\n" +
                "   <misstime></misstime>\n" +
                "   <playloop>3</playloop>\n" +
                "   <contenttype>0</contenttype>\n" +
                "   <playcontent>联动广播测试,联动广播测试,联动广播测试,联动广播测试,联动广播测试</playcontent>\n" +
                "   <members>7011</members>\n" +
                "</broadcast>\n" +
                "<!--adapter msg end-->";
        String end="<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                "<broadcast>\n" +
                "   <cmd>end</cmd>\n" +
                "   <uuid>"+uuid+"</uuid>\n" +
                "</broadcast>" +
                "<!--adapter msg end-->";
        try {


            MessageProcessor<String> processor = new MessageProcessor<String>() {
                @Override
                public void process(AioSession session, String msg) {
                    System.out.println("receive from server: " + msg);
                    if(client!=null){
                        client.shutdown();
                    }
                }
            };

             client = new AioQuickClient("10.10.23.112", 6006, new StringProtocol(), processor);
            AioSession session = client.start();
            WriteBuffer writeBuffer = session.writeBuffer();
            byte[] data = message.getBytes();
            writeBuffer.writeInt(data.length);
            writeBuffer.write(data);
            writeBuffer.flush();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        byte[] bytes = "设备标识：1456902".getBytes();
        int i = CRC16.CRC16_MODBUS(bytes);
        System.out.println(i);
        for (byte byteaa:bytes) {
            System.out.print(byteaa +"    ");
            System.out.println(Integer.toHexString(byteaa*-1));
        }
    }



}
